package com.huawei.appgallery.assistantdock.gamemode.card;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.viewpager.widget.ViewPager;
import com.huawei.appgallery.assistantdock.base.cardkit.bean.BuoyBaseCardBean;
import com.huawei.appgallery.assistantdock.base.cardkit.card.BuoyBaseCard;
import com.huawei.appgallery.assistantdock.gamemode.bean.CombineBuoyEnterCardBeanBuoy;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.gamebox.plugin.gameservice.bean.GameInfo;
import huawei.support.v4.widget.HwDotsPageIndicator;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import o.beo$e;
import o.beo$j;
import o.bid;
import o.big;
import o.bim;
import o.bim.c;
import o.biu;
import o.biu.a;
import o.cgz;
import o.Logger;
import o.fae;
import o.fam;
import o.PagerAdapter;
import org.jetbrains.annotations.NotNull;

public class CombineBuoyEnterCardBuoy extends BuoyBaseCard {
    private d ʻ;
    private d ʼ;
    private e ˊ;
    private List<a> ˋ = new ArrayList();
    private List<String> ˎ = new ArrayList();
    private GameInfo ˏ;
    private View ॱ;
    private boolean ॱॱ = false;

    class d extends PagerAdapter {
        private Context ʻ;
        final /* synthetic */ CombineBuoyEnterCardBuoy ˊ;
        private HashMap<Integer, View> ˋ = new HashMap();
        private bid ˎ;
        private List ˏ;
        private LayoutInflater ॱ;

        d(CombineBuoyEnterCardBuoy combineBuoyEnterCardBuoy, List list, Context context) {
            this.ˊ = combineBuoyEnterCardBuoy;
            this.ˏ = list;
            this.ॱ = LayoutInflater.from(context);
            this.ˎ = new bid(context);
            this.ʻ = context;
        }

        @NonNull
        public Object instantiateItem(@NonNull ViewGroup viewGroup, int i) {
            int ˏ = this.ˊ.ʼ();
            int i2 = ˏ * i;
            if (this.ॱ == null) {
                Logger.e("CombineCardVpAdapter", "instantiateItem error, inflater is null");
                return null;
            }
            LinearLayout linearLayout = (LinearLayout) this.ॱ.inflate(beo$j.ˏ, null, false);
            LayoutParams layoutParams = new LinearLayout.LayoutParams(viewGroup.getMeasuredWidth() / ˏ, -1);
            int i3 = i2;
            while (i3 < i2 + ˏ && i3 < this.ˏ.size()) {
                BuoyBaseEnterCard ˊ;
                View inflate = this.ॱ.inflate(beo$j.ʻ, null, false);
                final Object obj = this.ˏ.get(i3);
                if (i != 1 || i3 != (i2 + ˏ) - 1) {
                    ˊ = this.ˎ.ˊ(obj, false, this.ˊ.ॱॱ, "CONTENT");
                } else if (obj instanceof String) {
                    ˊ = this.ˎ.ˊ("all_service", false, this.ˊ.ॱॱ, "CONTENT");
                } else if (obj instanceof a) {
                    ˊ = this.ˎ.ˊ(a.ˏ("all_app", null, null, null), false, this.ˊ.ॱॱ, "CONTENT");
                } else {
                    ˊ = null;
                }
                if (ˊ != null) {
                    ˊ.ˏ(inflate);
                    ˊ.ˏ(new BuoyBaseCardBean());
                    linearLayout.addView(inflate, layoutParams);
                } else {
                    Logger.ˋ("CombineCardVpAdapter", "enterCard == null, do not add");
                    if (this.ʻ != null) {
                        new Handler(this.ʻ.getMainLooper()).post(new Runnable(this) {
                            final /* synthetic */ d ˏ;

                            public void run() {
                                this.ˏ.ˏ.remove(obj);
                                this.ˏ.notifyDataSetChanged();
                            }
                        });
                    } else {
                        Logger.e("CombineCardVpAdapter", "notifyDataSetChanged error, context is null.");
                    }
                }
                i3++;
            }
            viewGroup.addView(linearLayout);
            viewGroup.invalidate();
            this.ˋ.put(Integer.valueOf(i), linearLayout);
            return linearLayout;
        }

        public int getItemPosition(@NotNull Object obj) {
            return -2;
        }

        public void destroyItem(@NonNull ViewGroup viewGroup, int i, @NonNull Object obj) {
            viewGroup.removeView((View) this.ˋ.remove(Integer.valueOf(i)));
        }

        public int getCount() {
            if (this.ˏ == null) {
                return 0;
            }
            int size;
            if (this.ˏ.size() % this.ˊ.ʼ() == 0) {
                size = this.ˏ.size() / this.ˊ.ʼ();
            } else {
                size = (this.ˏ.size() / this.ˊ.ʼ()) + 1;
            }
            if (size <= 2) {
                return size;
            }
            return 2;
        }

        public boolean isViewFromObject(@NonNull View view, @NonNull Object obj) {
            return view == obj;
        }
    }

    class e extends Handler {
        final /* synthetic */ CombineBuoyEnterCardBuoy ॱ;

        e(CombineBuoyEnterCardBuoy combineBuoyEnterCardBuoy, Looper looper) {
            this.ॱ = combineBuoyEnterCardBuoy;
            super(looper);
        }

        public void handleMessage(Message message) {
            if (message == null) {
                Logger.e("CombineBuoyEnterCardBuoy", "Message is empty");
            } else if (message.what == 0) {
                this.ॱ.ˋ();
            }
        }
    }

    public CombineBuoyEnterCardBuoy(Context context) {
        super(context);
    }

    public cgz ˏ(View view) {
        this.ॱ = view;
        ʽ(view);
        ViewPager viewPager = (ViewPager) view.findViewById(beo$e.ߴ);
        ViewPager viewPager2 = (ViewPager) view.findViewById(beo$e.ـॱ);
        this.ˊ = new e(this, Looper.getMainLooper());
        this.ʻ = new d(this, this.ˎ, this.ʼॱ);
        this.ʼ = new d(this, this.ˋ, this.ʼॱ);
        viewPager.setAdapter(this.ʻ);
        viewPager2.setAdapter(this.ʼ);
        ((HwDotsPageIndicator) view.findViewById(beo$e.ﾞ)).setViewPager(viewPager);
        HwDotsPageIndicator hwDotsPageIndicator = (HwDotsPageIndicator) view.findViewById(beo$e.ꞌ);
        hwDotsPageIndicator.setViewPager(viewPager2);
        if (!big.ˏ()) {
            viewPager2.setVisibility(8);
            hwDotsPageIndicator.setVisibility(8);
        }
        return this;
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        if (this.ॱ != null) {
            this.ॱ.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener(this) {
                final /* synthetic */ CombineBuoyEnterCardBuoy ॱ;

                {
                    this.ॱ = r1;
                }

                public void onGlobalLayout() {
                    if (this.ॱ.ʻ != null) {
                        this.ॱ.ʻ.notifyDataSetChanged();
                        Logger.ˎ("CombineBuoyEnterCardBuoy", "rootView onGlobalLayout , serviceAdapter notifyDataSetChanged");
                    }
                    if (this.ॱ.ʼ != null) {
                        this.ॱ.ʼ.notifyDataSetChanged();
                        Logger.ˎ("CombineBuoyEnterCardBuoy", "rootView onGlobalLayout , freeformAdapter notifyDataSetChanged");
                    }
                    if (this.ॱ.ॱ != null) {
                        this.ॱ.ॱ.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    }
                }
            });
        }
        if (cardBean instanceof CombineBuoyEnterCardBeanBuoy) {
            CombineBuoyEnterCardBeanBuoy combineBuoyEnterCardBeanBuoy = (CombineBuoyEnterCardBeanBuoy) cardBean;
            fae ˏ = fam.ॱ().ˏ();
            if (ˏ != null) {
                this.ˏ = ˏ.getGameInfo();
            }
            this.ॱॱ = combineBuoyEnterCardBeanBuoy.ˊ();
            this.ˎ.clear();
            this.ˎ.addAll(ˏ(this.ˏ, this.ॱॱ));
            Logger.ˎ("CombineBuoyEnterCardBuoy", "serviceList = " + this.ˎ);
            this.ˋ.clear();
            this.ˋ.addAll(ॱ(this.ˏ, this.ॱॱ));
            Logger.ˎ("CombineBuoyEnterCardBuoy", "appList = " + this.ˋ);
            ʻ();
            if (this.ʻ != null) {
                this.ʻ.notifyDataSetChanged();
            }
            if (this.ʼ != null) {
                this.ʼ.notifyDataSetChanged();
            }
            Logger.ˏ("CombineBuoyEnterCardBuoy", "columNum = " + ʼ());
            return;
        }
        Logger.e("CombineBuoyEnterCardBuoy", "CardBean is not instanceof CombineBuoyEnterCardBeanBuoy");
    }

    private void ˊ() {
        if (this.ˊ != null) {
            this.ˊ.sendMessage(this.ˊ.obtainMessage(0));
        }
    }

    private void ˋ() {
        if (this.ʻ != null) {
            this.ʻ.notifyDataSetChanged();
        }
    }

    private int ʼ() {
        if (this.ʼॱ.getResources().getConfiguration().orientation == 1) {
            return 3;
        }
        return 4;
    }

    private List<String> ˏ(GameInfo gameInfo, boolean z) {
        List<String> ˏ = bim.ˏ(gameInfo, z);
        ˏ.remove("sound_to_vibrate_effect");
        if (!biu.ˋ().ॱˊ()) {
            ˏ.remove("device_setting");
        }
        if (!biu.ˋ().ᐝॱ() || this.ʼॱ.getResources().getConfiguration().orientation == 1) {
            ˏ.remove("virtual_key_setting");
        }
        if (!biu.ˋ().ˋ(gameInfo)) {
            ˏ.remove("net_optim");
        }
        return ˏ;
    }

    private List<a> ॱ(GameInfo gameInfo, boolean z) {
        return bim.ˊ(gameInfo, z);
    }

    private boolean ˎ(List<String> list, List<String> list2) {
        if (list == null || list2 == null) {
            return false;
        }
        if (list.size() != list2.size()) {
            return true;
        }
        for (int i = 0; i < list.size(); i++) {
            if (!((String) list.get(i)).equals(list2.get(i))) {
                return true;
            }
        }
        return false;
    }

    private void ʻ() {
        bim.ॱ(this.ʼॱ, this.ˏ, new c(this) {
            final /* synthetic */ CombineBuoyEnterCardBuoy ˋ;

            {
                this.ˋ = r1;
            }

            public void ॱ(List<String> list) {
                if (list != null) {
                    if (this.ˋ.ˎ(this.ˋ.ˎ, list)) {
                        Logger.ˏ("CombineBuoyEnterCardBuoy", "dataChanged");
                        this.ˋ.ˎ.clear();
                        this.ˋ.ˎ.addAll(list);
                        this.ˋ.ˊ();
                        return;
                    }
                    Logger.ˏ("CombineBuoyEnterCardBuoy", "dataChanged not");
                }
            }
        }, this.ॱॱ);
    }
}
